using Caliburn.Core.Metadata;
using Caliburn.PresentationFramework;
using Caliburn.PresentationFramework.ApplicationModel;
using Common.Model;
using Microsoft.Practices.ServiceLocation;

namespace HRManager.ViewModels
{
    using Common.Dao;

    [PerRequest(typeof(TrainingCourseViewModel))]
    public class TrainingCourseViewModel:MultiPresenter
    {
        public TrainingCourseViewModel(IServiceLocator locator, IRepository repository)
        {
            this._locator = locator;
            this._repository = repository;
        }

        private BindableCollection<TrainingCourse> _trainingCourses;
        private IRepository _repository;

        public BindableCollection<TrainingCourse> TrainingCourses
        {
            get { return _trainingCourses; }
            set { _trainingCourses = value; }
        }

        private TrainingCourseDetailViewModel _editTrainingCourse;
        private IServiceLocator _locator;

        public TrainingCourseDetailViewModel EditTrainingCourse
        {
            get { return _editTrainingCourse; }
            set 
            { 
                _editTrainingCourse = value; 
                NotifyOfPropertyChange(()=>this.EditTrainingCourse);
            }
        }

        public string HeaderInfo { get { return "Training Course"; } }

        public override void Activate()
        {
            base.Activate();
            var trainingCourses = this._repository.LoadAll<TrainingCourse, int>();
            this.TrainingCourses = new BindableCollection<TrainingCourse>(trainingCourses);
            var detialVM = this._locator.GetInstance<TrainingCourseDetailViewModel>();
            //detialVM.TrainingCourse = this.TrainingCourses[0];
            this.Open(detialVM);
            this.EditTrainingCourse = detialVM;
        }
    }
}